package org.example.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.bean.Person;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

@Slf4j
@RequestMapping("consume")
@RestController
public class ConsumeController {
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("hello/{name}")
    public Person hello(@PathVariable("name") String name) {
        Person p = restTemplate.getForObject("http://localhost:8001/provide/hello/" + name, Person.class);
        log.info("receive person: " + p);
        return p;
    }

    @PostMapping("test/cmd")
    public String cmd(@RequestBody String cmd) {
        String result = restTemplate.postForObject("http://localhost:8001/provide/test/cmd", cmd, String.class);
        log.info("receive result: " + result);
        return result;
    }
}
